﻿

using Lrd.Permissions.Core.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Lrd.Permissions
{

    public interface IRepository<TEntity, TPrimaryKey>
       where TEntity : IEntity<TPrimaryKey>

    {

        IQueryable<TEntity> Entities { get; }

        IQueryable<TEntity> TrackEntities { get; }


        /// <summary>
        /// 以主键查询
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>得到实体</returns>
        TEntity Get(TPrimaryKey id);

        /// <summary>
        /// 异步以主键查询
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>得到实体</returns>
        Task<TEntity> GetAsync(TPrimaryKey id);


        /// <summary>
        ///以条件查询
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <returns>得到实体</returns>
        TEntity Get(Expression<Func<TEntity, bool>> predicate);

        /// <summary>
        /// 异步以条件查询
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <returns>得到实体</returns>
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate);

        Task<int> InsertAsync(TEntity entitie);


        Task<int> UpdateAsync(TEntity entitie);

        Task<int> DeleteAsync(TEntity entitie);


        Task BatchRemoveAsync(Expression<Func<TEntity, bool>> predicate);

        Task<int> InsertAsync(params TEntity[] entities);

    }
}
